<template>
  <div>
    <!-- 查询参数及按钮部分 -->
    <div class="filter-container">
      <el-dialog v-dialogDrag :close-on-click-modal="false" title="查询" :visible.sync="dialogQueryFormVisible"
        style="padding:0px;" width="50%">
        <el-form ref="dataForm" class="dialog-Backgroundcolor" :model="listQuery" label-position="right"
          label-width="100px">
          <el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="工资类别：">
                  <el-select v-model="listQuery.meritPayCode" class="filter-item inputWidth" clearable
                    placeholder="--请选择--">
                    <el-option label="行政人员" value="0" />
                    <el-option label="事业人员" value="1" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="职务：">
                  <el-select v-model="listQuery.posCode" class="filter-item inputWidth" clearable placeholder="--请选择--">
                    <el-option v-for="item in posgrLists" :key="item.code" :label="item.name" :value="item.code" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="职级：">
                  <el-select v-model="listQuery.grCode" class="filter-item inputWidth" clearable placeholder="--请选择--">
                    <el-option v-for="item in grLists" :key="item.code" :label="item.name" :value="item.code" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="人员姓名：">
                  <el-input v-model="listQuery.personName" class="inputWidth" />
                </el-form-item>
              </el-col>

            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="身份证号码：">
                  <el-input v-model="listQuery.idenNo" class="inputWidth" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="人员类别：">
                  <el-select v-model="listQuery.state" class="filter-item" placeholder="--请选择--">
                    <el-option label="全部人员" value="" />
                    <el-option label="在职人员" value="3" />
                    <el-option label="离退休人员" value="1" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="请选择科室：">
                  <el-form-item prop="deptId">
                    <el-select ref="selectReport" v-model="listQuery.deptId" class="filter-item" placeholder="--请选择--"
                      :clearable="clearable" @clear="clearHandle">
                      <el-option :value="listQuery.deptId" :label="listQuery.deptName"
                        style="width: 300px;height:200px;overflow: auto;background-color:#fff">
                        <el-tree :data="listTree" :accordion="accordion" :props="defaultProps"
                          :node-key="defaultProps.id" :default-expanded-keys="defaultExpandedKey"
                          @node-click="handleDeptNodeClick" />
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="人员编码：">
                  <el-input v-model="listQuery.personnelCode" class="inputWidth" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-button type="primary" style="float:right;" @click="handleQuery">
              查询
            </el-button>

          </el-row>
        </el-form>
      </el-dialog>
      <el-row>

        <el-col :span="12">

          <el-select v-model="listQuery.state" class="filter-item" placeholder="--请选择--" @change="handleFilter">
            <el-option label="全部人员" value="" />
            <el-option label="在职人员" value="3" />
            <el-option label="离退休人员" value="1" />
          </el-select>

        </el-col>
      </el-row>
      <el-row>
        <el-col class="numCol">
          <span>单位名称：{{ unitName }} </span>
          <span> 在编人数：{{ registerNum }}人 其中：离退休：{{ quitNum }}人</span>
        </el-col>

      </el-row>
    </div>

    <!-- 表格部分 -->
    <vxe-table ref="singalTable" v-loading="listLoading" border="inner" :data="list" show-overflow
      :scroll-x="{ enabled: true, gt: 100, oSize: 100 }" :scroll-y="{ enabled: true, gt: 100, oSize: 100 }"
      :sort-config="{ trigger: 'cell', orders: ['desc', 'asc', null] }" row-id="personId" fit :height="tableHeight"
      class="my-test" :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
      :checkbox-config="{ trigger: 'row', highlight: true, range: true }" @cell-dblclick="editclick">
      <template slot="empty">
        <tableEmpty />
      </template>
      <vxe-table-column lable="" tree-node type="seq" min-width="80" fixed="left"></vxe-table-column>
      <vxe-table-column type="checkbox" width="50" fixed="left"></vxe-table-column>
      <vxe-table-column title="" align="center" width="50" fixed="left">
        <template slot-scope="{row}">
          <i v-if="row.existsFile == 1" class="el-icon-paperclip file-logo" />
        </template>
      </vxe-table-column>
      <vxe-table-column v-if="tabPane == 'all'" title="变动状态" align="center" width="100" fixed="left">
        <template slot-scope="{row}">
          <span>{{ row.operateCode | changeFlag(row, that) }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column v-if="tabPane != 'all'" title="增减情况" align="center" width="100" fixed="left">
        <template slot-scope="{row}">
          <span>{{ row.operateCode | changeFlag(row, that) }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column v-if="tabPane != 'all'" title="变动原因" align="center" width="120" fixed="left">
        <template slot-scope="{row}">
          <span>{{ row.deleteType | parseReason(row) }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column title="科室" align="center" width="100" fixed="left" sortable>
        <template slot-scope="{row}">
          <span>{{ row.deptId | deptFilter(that) }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column prop="personnelCode" title="人员编码" align="center" width="100" fixed="left" sortable>
        <template slot-scope="{row}">
          <span>{{ row.personnelCode }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column title="姓名" min-width="100" field="personName" fixed="left" sortable>
        <template slot-scope="{row}">
          <el-link type="primary" @click="viewInfo(row)">
            <span>{{ row.personName }}</span>
          </el-link>
        </template>
      </vxe-table-column>
      <vxe-table-column prop="idenNo" title="身份证号码" align="center" width="200" sortable>
        <template slot-scope="{row}">
          <span>{{ row.idenNo }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column title="性别" align="center" width="100">
        <template slot-scope="{row}">
          <span>{{ row.sexCode | sexFilter(that) }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column prop="meritPayCode" title="工资类别" align="center" width="200" sortable>
        <template slot-scope="{row}">
          <span>{{ row.meritPayCode | meritPayCodeFilter(that) }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column v-if='IsfuncName == 1' prop="funcName" title="功能分类" align="center" width="200" sortable>
        <template slot-scope="{row}">
          <span>{{ row.funcName }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column title="民族" align="center" width="100">
        <template slot-scope="{row}">
          <span>{{ row.natCode | natFilter(that) }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column title="人员状态" align="center" width="100">
        <template slot-scope="{row}">
          <span>{{ row.state | personFlagFilter(that) }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column title="学历" align="center" width="100">
        <template slot-scope="{row}">
          <span>{{ row.schRecCode | schrecFilter(that) }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column title="职务" align="center" width="120">
        <template slot-scope="{row}">
          <span>{{ row.posCode | posgrFilter(that) }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column title="职级" align="center" width="100">
        <template slot-scope="{row}">
          <span>{{ row.grCode | grFilter(that) }}</span>
        </template>
      </vxe-table-column>
      <!--      <vxe-table-column-->
      <!--        label="是否在编"-->
      <!--        align="center"-->
      <!--        width="100"-->
      <!--      >-->
      <!--        <template slot-scope="{row}">-->
      <!--          <span>{{ row.isAuth | authFilter(that) }}</span>-->
      <!--        </template>-->
      <!--      </vxe-table-column>-->
      <vxe-table-column title="工资级别" align="center" width="100">
        <template slot-scope="{row}">
          <span>{{ row.salaGrCode | salagrFilter(that) }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column title="出生日期" align="center" width="100">
        <template slot-scope="{row}">
          <span>{{ row.birthday }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column title="入职时间" align="center" width="100">
        <template slot-scope="{row}">
          <span>{{ row.enterAgencyDate }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column title="离退休时间" align="center" width="100">
        <template slot-scope="{row}">
          <span>{{ row.retireDate }}</span>
        </template>
      </vxe-table-column>
      <vxe-table-column title="参加工作时间" align="center" width="120">
        <template slot-scope="{row}">
          <span>{{ row.workInitDate }}</span>
        </template>
      </vxe-table-column>
    </vxe-table>
    <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    <!-- 新增页面 -->
    <el-dialog v-dialogDrag :close-on-click-modal="false" :title="addDialogTitle" :visible.sync="addFormVisible"
      width="50%">
      <el-form class="addForm dialog-backgroundcolor">
        <el-row>
          <span class="selectSpan">请选择人员类型：</span>
        </el-row>
        <el-row class="addSelectRow">
          <el-form-item>
            <el-select v-model="formData.state" class="filter-item" placeholder="--请选择--">
              <el-option label="在职人员" value="3" />
              <el-option label="离退休人员" value="1" />
            </el-select>
          </el-form-item>
        </el-row>
        <el-row class="addButRow">
          <el-button type="primary" @click="handleAddDialog()">
            新增
          </el-button>
          <el-button @click="addFormVisible = false">
            取消
          </el-button>
        </el-row>
        <el-row class="addTitpsRow">
          <span class="addTitps">注意：不同的人员类型需要的信息项是不同的，请务必正确选择人员类型。</span>
        </el-row>
      </el-form>
    </el-dialog>

    <!-- 在职人员页面部分 -->
    <el-dialog v-dialogDrag :close-on-click-modal="false" :title="dialogStatus" :visible.sync="registerFormVisible"
      width="70%">
      <el-tabs v-model="activeName" class="dialog-Backgroundcolor" @tab-click="tabChange">
        <el-tab-pane label="在职人员" style="margin-left:4%" name="personInfo">
          <el-form ref="registerForm" class="dialog-Backgroundcolor" :rules="registerFormRules" :model="formData"
            label-position="top" size="small">

            <el-row style="margin-left:60px;">
              <el-col :span="8">
                <el-form-item label="单位代码：" prop="agencyCode" />
                <el-input v-model="formData.agencyCode" disabled />
              </el-col>
              <el-col :span="8">
                <el-form-item label="单位名称：" prop="agencyName" />
                <el-input v-model="formData.agencyName" disabled />
              </el-col>

              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="工资类型：" prop="meritPayCode">
                    <el-select v-model="formData.meritPayCode" class="filter-item" placeholder="--请选择--"
                      @change="getPersonSalaryInfoByPersonType">
                      <el-option v-for="item in salaryTypes" v-show="item.state != '1'" :key="item.code"
                        :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
            </el-row>
            <el-row style="margin-left:60px; margin-top:15px;">
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="姓名：" prop="personName">
                    <el-input v-model="formData.personName" maxlength="38" />
                  </el-form-item>

                </div>
              </el-col>
              <el-col :span="8">
                <div class="redstar">

                  <el-form-item label="性别：" prop="sexCode">
                    <el-select v-model="formData.sexCode" class="filter-item" placeholder="--请选择--">
                      <el-option v-for="item in sexLists" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="redstar">

                  <el-form-item label="民族：" prop="natCode">
                    <el-select v-model="formData.natCode" class="filter-item" placeholder="--请选择--">
                      <el-option v-for="item in natLists" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
            </el-row>
            <el-row style="margin-left:60px;margin-top:15px;">
              <el-col :span="8">
                <div class="redstar">

                  <el-form-item label="证件类型：" prop="idenTypeCode">
                    <!-- :disabled="isEdit" -->
                    <el-select v-model="formData.idenTypeCode" class="filter-item" placeholder="--请选择--">
                      <el-option v-for="item in citTypeLists" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="redstar">

                  <el-form-item label="证件号码：" prop="idenNo">
                    <!-- :disabled="isEdit" -->
                    <el-input v-model="formData.idenNo" maxlength="18" @blur="getName(formData.idenNo)" />
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="8">
                <el-form-item label="出生日期：" prop="birthday" />
                <el-date-picker v-model="formData.birthday" type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                  placeholder="出生日期" :disabled="isEdit" />
              </el-col>
            </el-row>
            <el-row style="margin-left:60px;margin-top:15px;">
              <el-col :span="8">
                <el-form-item label="学历：" prop="schRecCode" />
                <el-select v-model="formData.schRecCode" class="filter-item" clearable placeholder="--请选择--">
                  <el-option v-for="item in schrecLists" :key="item.code" :label="item.name" :value="item.code" />
                </el-select>
              </el-col>
              <el-col :span="8">
                <el-form-item label="人员类型：" prop="personTypeCode" />
                <el-select v-model="formData.personTypeCode" class="filter-item" clearable placeholder="--请选择--">
                  <el-option v-for="item in salaryTypes" v-show="item.state == 0 || item.state == '3'" :key="item.code"
                    :label="item.name" :value="item.code" />
                </el-select>
              </el-col>
              <el-col :span="8">
                <el-form-item label="参加工作时间：" prop="workInitDate" />
                <el-date-picker v-model="formData.workInitDate" type="date" format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd" placeholder="参加工作时间" />
              </el-col>
            </el-row>
            <el-row style="margin-left:60px;margin-top:15px;">
              <el-col :span="8">
                <el-form-item label="进入本单位时间：" prop="enterAgencyDate" />
                <el-date-picker v-model="formData.enterAgencyDate" type="date" format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd" placeholder="进入本单位时间" />
              </el-col>
              <el-col :span="8">
                <el-form-item label="技术等级：" prop="tecGrCode" />
                <el-select v-model="formData.tecGrCode" class="filter-item" clearable placeholder="--请选择--">
                  <el-option v-for="item in tecgrLists" :key="item.code" :label="item.name" :value="item.code" />
                </el-select>
              </el-col>
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="人员身份：" prop="personIdeCode">
                    <el-select v-model="formData.personIdeCode" class="filter-item" placeholder="--请选择--">
                      <el-option v-for="item in personPerideLists" :key="item.code" :label="item.name"
                        :value="item.code" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
            </el-row>
            <el-row style="margin-left:60px;margin-top:15px;">
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="人员类别工资类型：：" prop="personTypeId">
                    <el-select v-model="formData.personTypeId" class="filter-item" placeholder="--请选择--"
                      @change="queryPostList">
                      <el-option v-for="item in personTypeList" :key="item.id" :label="item.name" :value="item.id" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="职务：" prop="postId">
                    <el-select v-model="formData.postId" class="filter-item" placeholder="--请选择--"
                      @change="queryGradeLevelList">
                      <el-option v-for="item in postList" :key="item.id" :label="item.name" :value="item.id" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="档次：" prop="gradeId">
                    <el-select v-model="formData.gradeId" class="filter-item" placeholder="--请选择--"
                      @change="getSalaryByGradeLevel">
                      <el-option v-for="item in gradeList" :key="item.id" :label="item.name" :value="item.id" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
            </el-row>
            <el-row style="margin-left:60px;margin-top:15px;">
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="级别：" prop="levelId">
                    <el-select v-model="formData.levelId" class="filter-item" placeholder="--请选择--"
                      @change="getSalaryByGradeLevel">
                      <el-option v-for="item in levelList" :key="item.id" :label="item.name" :value="item.id" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="工资卡开户银行：" prop="salaCardBank">
                    <el-select v-model="formData.salaCardBank" :disabled="disable" class="filter-item"
                      placeholder="--请选择--">
                      <el-option v-for="item in agencyBankLists" :key="item.code" :label="item.name"
                        :value="item.code" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="工资卡卡号：" prop="salaCardNo">
                    <el-input v-model="formData.salaCardNo" maxlength="60" />
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="人员状态：" prop="state">
                    <el-select v-model="formData.state" class="filter-item" placeholder="--请选择--">
                      <el-option label="在职人员" value="3" />
                      <el-option label="离退休人员" value="1" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="手机号：" prop="phone">
                    <el-input v-model="formData.phone" maxlength="14" />
                  </el-form-item>

                </div>
              </el-col>
              <el-col :span="8" v-if='IsfuncName == 1'>
                <el-form-item label="支出功能科目:" prop="funcName" />
                <el-select ref="selectReport" v-model="formData.funcName" class="filter-item" clearable
                  placeholder="--请选择--" style="width:100%" @clear="clearHandle">
                  <el-option :value="formData.funcCode" :label="funcName"
                    style="height:200px;overflow: auto;background-color:#fff">
                    <el-tree :data="funcLists" :accordion="true" :highlight-current="true" :props="defaultProps"
                      :node-key="defaultProps.id" :default-expanded-keys="defaultExpandedKey"
                      @node-click="handleFuncNodeClick" />
                  </el-option>
                </el-select>
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="工资信息" style="margin-left:4%" name="salaryInfo" @change="checkisChangedPersonType">
          <el-form ref="salaryInfoForm" :model="formData" label-position="top" label-width="140px" size="small">
            <el-row>
              <el-col v-for="salary in personSalaryLists" :key="salary.keyId" :span="8">
                <el-form-item :label="salary.name">
                  <vxe-input v-show="salary.isCompute != '1'" v-model="salary.value" placeholder="" type="float"
                    align="right" max="99999999" clearable @keyup.enter.native="nextInput($event)" />
                  <vxe-input v-show="salary.isCompute == 1" disabled v-model="salary.value" placeholder="" type="float"
                    align="right" max="99999999" clearable @keyup.enter.native="nextInput($event)" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="附件" style="margin-left:4%" name="enclosure">
          <file ref="fileRef" :middle-table-code="2" />
        </el-tab-pane>
        <el-row>
          <el-col :span="24" style="text-align: center;margin-top:20px">
            <el-button type="primary" :loading="registerLoading" @click="handleAddPerson('registerForm')">保存
            </el-button>
            <el-button @click="registerFormVisible = false">取消</el-button>
          </el-col>
        </el-row>
      </el-tabs>
    </el-dialog>
    <!-- 离休人员页面-->
    <el-dialog v-dialogDrag :close-on-click-modal="false" :title="dialogStatus" :visible.sync="quitFormVisible"
      width="60%">
      <el-tabs v-model="activeName" class="dialog-Backgroundcolor" @tab-click="tabChange">
        <el-tab-pane label="离退休人员" style="margin-left:4%" name="personInfo">
          <el-form ref="quitForm" class="dialog-Backgroundcolor" :rules="quitFormRules" :model="formData"
            label-position="top" size="small">
            <el-row style="margin-left:45px">
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="姓名：" prop="personName">
                    <el-input v-model="formData.personName" maxlength="38" />
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="性别：" prop="sexCode">
                    <el-select v-model="formData.sexCode" class="filter-item" placeholder="--请选择--">
                      <el-option v-for="item in sexLists" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="工资类型：" prop="meritPayCode">
                    <el-select v-model="formData.meritPayCode" class="filter-item" placeholder="--请选择--"
                      @change="getPersonSalaryInfoByPersonType">
                      <el-option v-for="item in salaryTypes" v-show="item.state == 0 || item.state == '1'"
                        :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>

            </el-row>
            <el-row style="margin-left:45px;margin-top:15px">
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="民族：" prop="natCode">
                    <el-select v-model="formData.natCode" class="filter-item" placeholder="--请选择--">
                      <el-option v-for="item in natLists" :key="item.code" :label="item.name" :value="item.code" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="身份证号码：" prop="idenNo">
                    <!-- :disabled="isEdit" -->
                    <el-input v-model="formData.idenNo" maxlength="18" @blur="getName(formData.idenNo)" />
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="8">
                <el-form-item label="出生日期：" prop="birthday" />
                <el-date-picker v-model="formData.birthday" type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                  placeholder="出生日期" :disabled="isEdit" />
              </el-col>

            </el-row>
            <el-row style="margin-left:45px;margin-top:15px">
              <el-col :span="8">
                <el-form-item label="参加工作时间：" prop="workInitDate" />
                <el-date-picker v-model="formData.workInitDate" type="date" format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd" placeholder="参加工作时间" @change="calculationWorkYear('workInitDate')" />
              </el-col>
              <el-col :span="8">
                <el-form-item label="离退休时间：" prop="retireDate" />
                <el-date-picker v-model="formData.retireDate" type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                  placeholder="离退休时间" @change="calculationWorkYear('retireDate')" />
              </el-col>
              <el-col :span="8">
                <el-form-item label="工龄：" prop="workingYear" />
                <el-input v-model="formData.workingYear" disabled />
              </el-col>

            </el-row>
            <el-row style="margin-left:45px;margin-top:15px">

              <el-col :span="8">
                <el-form-item label="退休时职级：" prop="grCode" />
                <el-select v-model="formData.grCode" class="filter-item" clearable placeholder="--请选择--">
                  <el-option v-for="item in grLists" :key="item.code" :label="item.name" :value="item.code" />
                </el-select>
              </el-col>
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="工资卡开户银行：" prop="salaCardBank">
                    <el-select v-model="formData.salaCardBank" :disabled="disable" class="filter-item"
                      placeholder="--请选择--">
                      <el-option v-for="item in agencyBankLists" :key="item.code" :label="item.name"
                        :value="item.code" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="工资卡卡号：" prop="salaCardNo">
                    <el-input v-model="formData.salaCardNo" maxlength="60" />
                  </el-form-item>

                </div>
              </el-col>
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="人员状态：" prop="state">
                    <el-select v-model="formData.state" class="filter-item" placeholder="--请选择--">
                      <el-option label="在职人员" value="3" />
                      <el-option label="离退休人员" value="1" />
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="redstar">
                  <el-form-item label="手机号：" prop="phone">
                    <el-input v-model="formData.phone" maxlength="14" />
                  </el-form-item>

                </div>
              </el-col>
              <el-col :span="8" v-if='IsfuncName == 1'>
                <el-form-item label="支出功能科目:" prop="funcName" />
                <el-select ref="selectReport" v-model="formData.funcName" class="filter-item" clearable
                  placeholder="--请选择--" style="width:100%" @clear="clearHandle">
                  <el-option :value="formData.funcCode" :label="funcName"
                    style="height:200px;overflow: auto;background-color:#fff">
                    <el-tree :data="funcLists" :accordion="true" :highlight-current="true" :props="defaultProps"
                      :node-key="defaultProps.id" :default-expanded-keys="defaultExpandedKey"
                      @node-click="handleFuncNodeClick" />
                  </el-option>
                </el-select>
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="工资信息" style="margin-left:4%" name="salaryInfo" @change="checkisChangedPersonType">
          <el-form ref="salaryInfoForm" :model="formData" label-position="top" label-width="140px" size="small">
            <el-row>
              <el-col v-for="salary in personSalaryLists" :key="salary.keyId" :span="8">
                <el-form-item :label="salary.name">
                  <vxe-input v-show="salary.isCompute != 1" v-model="salary.value" placeholder="" type="float"
                    align="right" max="99999999" clearable @keyup.enter.native="nextInput($event)" />
                  <vxe-input v-show="salary.isCompute == 1" disabled v-model="salary.value" placeholder="" type="float"
                    align="right" max="99999999" clearable @keyup.enter.native="nextInput($event)" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="附件" style="margin-left:4%" name="enclosure">
          <file ref="fileRef" :middle-table-code="2" />
        </el-tab-pane>
        <el-row>
          <el-col :span="24" style="text-align: center;margin-top:20px">
            <el-button type="primary" :loading="registerLoading" @click="handleAddPerson('quitForm')">保存</el-button>
            <el-button @click="quitFormVisible = false">取消</el-button>
          </el-col>
        </el-row>
      </el-tabs>

    </el-dialog>
    <!-- 调出页面  -->
    <el-dialog v-dialogDrag :close-on-click-modal="false" title="调出" :visible.sync="outFormVisible" width="70%"
      max-height="500px">
      <el-form ref="outForm" :rules="outFormRules" class="dialog-Backgroundcolor" :model="formData" label-position="top"
        size="small">
        <el-row class="el-row-out">
          <el-col :span="16">
            <el-row>
              <el-col :span="11">
                <el-form-item label="人员姓名：" prop="personName" />
                <el-input v-model="formData.personName" class="inputWidth" disabled />
              </el-col>
              <el-col :span="11">
                <el-form-item label="证件号码：" prop="idenNo" />
                <el-input v-model="formData.idenNo" class="inputWidth" disabled />
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="11">
                <el-form-item label="原单位代码：" prop="agencyCode" />
                <el-input v-model="formData.agencyCode" class="inputWidth" disabled />
              </el-col>
              <el-col :span="11">
                <el-form-item label="原单位名称：" prop="agencyName" />
                <el-input v-model="formData.agencyName" class="inputWidth" disabled />
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="11">
                <el-form-item label="生效时间：" prop="startDate" />
                <el-date-picker v-model="formData.startDate" type="date" disabled class="inputWidth" format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd" placeholder="生效时间" />
              </el-col>
              <el-col :span="11">
                <el-form-item label="去向单位：" prop="toAgencyName">
                  <el-input v-model="formData.toAgencyName" clearable />
                </el-form-item>

              </el-col>
              <!-- <el-col :span="1">
                <el-button type="primary" icon="el-icon-position" circle @click="handleShowTree" />
              </el-col> -->
            </el-row>
            <el-row>
              <el-col :span="16" style="margin-top:20px;text-align:center; margin-left:50px">
                <el-button type="primary" :loading="outLoading" @click="handleOutSave">
                  保存
                </el-button>
                <el-button @click="outFormVisible = false">
                  取消
                </el-button>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="20" class="tipsCol">
                <span class="tipsSpan">请从右侧单位树选择去向单位（调入单位）。调到外省的人员应从【消减】入口录入，按照人员【消减】处理。操作时，应上传相关的调转文件到系统中。</span>
              </el-col>
            </el-row>
          </el-col>
          <el-col :span="8">
            <el-row>
              <el-tree ref="tree" :data="agencyData" :props="defaultProps" :filter-node-method="filterNode"
                node-key="code" :default-expanded-keys="['0']" class="el-tree-out" style="height:413px"
                @node-click="handleNodeClick" />
            </el-row>
          </el-col>
        </el-row>
      </el-form>
      <file ref="fileRef" :middle-table-code="2" />
    </el-dialog>
    <!-- 消减页面  -->
    <el-dialog v-dialogDrag :close-on-click-modal="false" title="人员消减" :visible.sync="reductionFormVisible" width="55%"
      max-height="500px">
      <el-form ref="reductionForm" class="dialog-Backgroundcolor" :rules="reductionFormRules" :model="formData"
        label-position="top" size="small">
        <el-row>
          <el-col :span="8">
            <el-form-item label="单位代码：" prop="agencyCode" />
            <el-input v-model="formData.agencyCode" disabled />
          </el-col>
          <el-col :span="8">
            <el-form-item label="单位名称：" prop="agencyName" />
            <el-input v-model="formData.agencyName" disabled />
          </el-col>
          <el-col :span="8">
            <div class="redstar">
              <el-form-item label="工资类别：" prop="meritPayCode" />
              <el-select v-model="formData.meritPayCode" class="filter-item inputWidth" placeholder="--请选择--"
                @change="getPersonSalaryInfoByPersonType" disabled>
                <el-option v-for="item in salaryTypes" :key="item.code" :label="item.name" :value="item.code" />
              </el-select>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="姓名：" prop="personName" />
            <el-input v-model="formData.personName" disabled />
          </el-col>
          <el-col :span="8">
            <el-form-item label="性别：" prop="sexCode" />
            <el-select v-model="formData.sexCode" class="filter-item inputWidth" placeholder="--请选择--" disabled>
              <el-option v-for="item in sexLists" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-col>
          <el-col :span="8">
            <el-form-item label="民族：" prop="natCode" />
            <el-select v-model="formData.natCode" class="filter-item inputWidth" placeholder="--请选择--" disabled>
              <el-option v-for="item in natLists" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="证件类型：" prop="idenTypeCode" />
            <el-select v-model="formData.idenTypeCode" class="filter-item inputWidth" placeholder="--请选择--" disabled>
              <el-option v-for="item in citTypeLists" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-col>
          <el-col :span="8">
            <el-form-item label="证件号码：" prop="idenNo" />
            <el-input v-model="formData.idenNo" class="inputWidth" disabled />
          </el-col>
          <el-col :span="8">
            <el-form-item label="出生日期：" prop="birthday" />
            <el-date-picker v-model="formData.birthday" class="inputWidth" type="date" format="yyyy-MM-dd"
              value-format="yyyy-MM-dd" placeholder="出生日期" disabled />
          </el-col>
        </el-row>
        <el-row>
          <!-- <el-col class="reductionTipsCol">
            <span class="reductionTips">温馨提示：请确认上面信息无误后进行再进行下面的减员操作和上传相关文件。</span>
          </el-col> -->
        </el-row>
        <el-row>
          <el-col :span="8">
            <div class="redstar">
              <el-form-item label="人员消减类型：" prop="deleteType">
                <el-select v-model="formData.deleteType" class="filter-item inputWidth" placeholder="--请选择--">
                  <el-option label="调出删除" value="0" />
                  <el-option label="办理退休" value="1" />
                  <el-option label="去世消减" value="2" />
                </el-select>
              </el-form-item>保存
            </div>
          </el-col>
          <el-col :span="8">

            <el-form-item label="生效时间：" prop="startDate">
              <el-date-picker v-model="formData.startDate" class="inputWidth" disabled type="date" format="yyyy-MM-dd"
                value-format="yyyy-MM-dd" placeholder="生效时间" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="16" style="text-align: center;margin-left:150px; margin-top:20px">
            <el-button type="primary" :loading="reducationLoading" @click="handleReducationSave">
              保存
            </el-button>
            <el-button @click="reductionFormVisible = false">
              取消
            </el-button>
          </el-col>
        </el-row>
      </el-form>
      <file ref="fileRef" :middle-table-code="2" />
    </el-dialog>
    <el-dialog v-dialogDrag :close-on-click-modal="false" title="导入" :visible.sync="dialogImportFormVisible"
      width="29%">
      <el-upload class="upload-demo" drag style="padding-left:2px" action="#" list-type="multipart/form-data"
        accept=".xls,.xlsx" :show-file-list="false" :http-request="uploadExcel">
        <i class="el-icon-upload" />
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div slot="tip" class="el-upload__tip" />
      </el-upload>

    </el-dialog>
    <!-- 跨行修改  -->
    <el-dialog v-dialogDrag :close-on-click-modal="false" :title="updateStatus" :visible.sync="updateFormVisible"
      width="40%">
      <el-form ref="quitBankForm" class="dialog-Backgroundcolor" :rules="quitFormRules" :model="formData"
        label-position="top" size="small">
        <el-row style="margin-left:20px">
          <el-col :span="12">
            <div class="redstar">
              <el-form-item label="姓名：" prop="personName">
                <el-input v-model="formData.personName" maxlength="38" disabled />
              </el-form-item>
            </div>
          </el-col>

          <el-col :span="12">
            <div class="redstar">
              <el-form-item label="身份证号码：" prop="idenNo">
                <!-- :disabled="isEdit" -->
                <el-input v-model="formData.idenNo" maxlength="18" disabled @blur="getName(formData.idenNo)" />
              </el-form-item>
            </div>
          </el-col>
        </el-row>

        <el-row style="margin-left:20px;margin-top:15px">
          <el-col :span="12">
            <div class="redstar">
              <el-form-item label="工资卡开户银行：" prop="salaCardBank">
                <el-select v-model="formData.salaCardBank" :disabled="disable" class="filter-item"
                  placeholder="--请选择--">
                  <el-option v-for="item in agencyBankLists" :key="item.code" :label="item.name" :value="item.code" />
                </el-select>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="redstar">
              <el-form-item label="工资卡卡号：" prop="salaCardNo">
                <el-input v-model="formData.salaCardNo" maxlength="60" />
              </el-form-item>

            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24" style="text-align: center;margin-top:30px">
            <el-button type="primary" :loading="updateFormVisibleLoading"
              @click="handleAddPersonupdate('quitBankForm')">
              保存
            </el-button>
            <el-button @click="updateFormVisible = false">
              取消
            </el-button>
          </el-col>
        </el-row>
      </el-form>

    </el-dialog>
    <Enclosure ref="enc" :middle-table-code="2" />
    <PersonSalaryInfo ref="personSalaryInfo" />
  </div>
</template>
<script>
import {
  generateFormula,
  submitData
} from '@/api/unitSalaryReport/unitSalaryReport'
import { getPersonSalaryInfo, queryExistingNumber, queryAgencyPersonRestrict } from '@/api/personInfoMaintenance/archiveQuery'
import { getDepartmentList, getDepartmentTree } from '@/api/unitInformationMaintenance/internalOrganizationMaintenance'
import {
  getPersonOperateList,
  savePersonInfo,
  revokeOperate,
  getStateNum,
  queryAgencyInfoById,
  outPutPersonOperateList,
  queryPersonFileNum,
  personApproved,
  rejectPersonApproved
} from '@/api/personInfoMaintenance/personChangeEditStandard'
import {
  getSex,
  getNat,
  getCitType,
  getSchrec,
  getPosgr,
  getAgencyPeride,
  getFundmode,
  getGr,
  getTecgr,
  getSalagr,
  getAgencyBank,
  getCountry,
  getAgencyTree,
  Export,
  Import,
  getSalaryState,
  getSalaryType,
  getConfigCtrlByTypeMof,
  getBaseDataFunc,
  getfuncName
} from '@/api/baseInfo'
import { querySalPostByPersonTypeId, querySalPersonTypeAll, querySalPostGradeLevelAll, getSalByGradeLevelId } from '@/api/salaryConfigManage/personTypePostConfig'
import { getAgencyVerifyByAgencyId } from '@/api/agencyVerify'
import Enclosure from '@/components/Enclosure'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import tableEmpty from '@/components/table/empty'
import PersonSalaryInfo from '@/components/personSalaryInfo/personSalaryInfo'
import file from './file'
export default {
  name: 'Unit',
  components: { Pagination, tableEmpty, Enclosure, PersonSalaryInfo, file },
  directives: { waves },
  //声明过滤器
  filters: {
    deptNameFilter(value, that) {
      const deptNames = that.deptNames
      for (const item of deptNames) {
        if (value === item.code) {
          return item.name
        }
      }
    },
    changeFlag(type, row, that) {
      const verifyState = row.verifyState
      if (row.verifyState === '2' && row.isReal === 0) {
        let value = ''
        if (type === 'add') {
          value = '增员'
        } else if (type === 'edit') {
          value = '修改'
        } else if (type === 'in') {
          value = '增员'
        } else if (type === 'out') {
          value = '减员'
        } else if (type === 'delete') {
          value = '消减'
        }
        return value + '-待生效'
      } else if (
        ((type === 'add' && verifyState === '2') ||
          (type === 'edit' && verifyState === '2') ||
          (type === 'in' && verifyState === '2')) && that.tabPane !== '2'
      ) {
        return '正常'
      } else if (type === 'in' && verifyState === null) {
        return '待调入'
      } else if (type === 'add') {
        return '增员'
      } else if (type === 'edit') {
        return '修改'
      } else if (type === 'out') {
        return '减员'
      } else if (type === 'in') {
        return '增员'
      } else if (type === 'delete') {
        return '消减'
      }
    },
    parseReason(type, row) {
      if (row.operateCode === 'add') {
        return '新增'
      } else if (row.operateCode === 'edit') {
        return '修改人员信息'
      } else if (row.operateCode === 'out') {
        return '省内调出'
      } else if (row.operateCode === 'in') {
        return '省内调入'
      } else if (type === '0') {
        return '调出删除'
      } else if (type === '1') {
        return '办理退休'
      } else if (type === '2') {
        return '去世消减'
      }
    },
    // 部门过滤器
    deptFilter(type, that) {
      const deptLists = that.deptNames
      for (const item in deptLists) {
        if (deptLists[item].code === type) {
          return deptLists[item].name
        }
      }
    },
    // 性别过滤器
    sexFilter(type, that) {
      const sexLists = that.sexLists
      for (const item in sexLists) {
        if (sexLists[item].code === type) {
          return sexLists[item].name
        }
      }
    },
    // 人员类型过滤器
    meritPayCodeFilter(type, that) {
      const salaryTypes = that.salaryTypes
      for (const item in salaryTypes) {
        if (salaryTypes[item].code === type) {
          return salaryTypes[item].name
        }
      }
    },
    // 民族过滤器
    natFilter(type, that) {
      const natLists = that.natLists
      for (const item in natLists) {
        if (natLists[item].code === type) {
          return natLists[item].name
        }
      }
    },
    // 学历过滤器
    schrecFilter(type, that) {
      const schrecLists = that.schrecLists
      for (const item in schrecLists) {
        if (schrecLists[item].code === type) {
          return schrecLists[item].name
        }
      }
    },
    // 职务过滤器
    posgrFilter(type, that) {
      const posgrLists = that.posgrLists
      for (const item in posgrLists) {
        if (posgrLists[item].code === type) {
          return posgrLists[item].name
        }
      }
    },
    // 职级过滤器
    grFilter(type, that) {
      const grLists = that.grLists
      for (const item in grLists) {
        if (grLists[item].code === type) {
          return grLists[item].name
        }
      }
    },
    // 工资级别过滤器
    salagrFilter(type, that) {
      const salagrLists = that.salagrLists
      for (const item in salagrLists) {
        if (salagrLists[item].code === type) {
          return salagrLists[item].name
        }
      }
    },
    // 人员状态过滤器
    personFlagFilter(type, that) {
      if (type === '1') {
        return '离退休'
      } else if (type === '3') {
        return '在职'
      }
    },
    //号码脱敏显示
    hideMiddle(val) {
      if (val !== undefined && val !== null) {//避免列表中存在空数据报错
        return `${val.substring(0, 4)}****${val.substring(val.length - 4)}`
      } else {
        return val
      }
    },
    // 是否在编过滤器
    authFilter(type, that) {
      if (type === 1) {
        return '是'
      } else if (type === 0) {
        return '否'
      }
    }
  },
  props: ['tabPane', 'treeData'],
  data() {
    return {
      accordion: false,
      defaultProps: {
        id: 'id',
        children: 'children',
        label: 'label'
      },
      deptLists: [], // 部门科室
      deptNames: [],
      defaultExpandedKey: [],
      listTree: [],
      funcName: '',
      clearable: true,
      computeFormula: [],
      treeClickCount: 0, // 记录调出树点击（单机还是双击）
      activeName: 'personInfo', // 默认页签显示第一项
      personSalaryLists: [], // 人员工资数据集合
      tableHeight: null,
      disable: false,
      salaryState: '',
      configCtrl: '1',
      bank: [],
      openenClose: true,
      selection: [],
      checkList: [],
      dialogQueryFormVisible: false,
      that: this,
      unitName: '',
      registerNum: '0',
      agencyPersonRestrict: '',//编制数限制数
      existingNumber: '',//现有人数
      quitNum: '0',
      list: [],
      total: 0,
      listLoading: false,
      listQuery: {
        deptName: '',
        deptId: '',
        page: 1,
        limit: 200,
        meritPayCode: '',
        posCode: '',
        grCode: '',
        personName: '',
        idenNo: '',
        flag: 'all',
        state: '',
        agencyId: '0',
        agencyCode: '',
        agencyName: '',
        personnelCode: '',
        organization:3
      },
      formData: {
        
        deptName: '',
        deptId: '',
        id: '',
        personId: '',
        state: '',
        operateCode: '',
        agencyId: '',
        agencyCode: '',
        agencyName: '',
        meritPayCode: '',
        personName: '',
        sexCode: '',
        natCode: '',
        idenTypeCode: '',
        idenNo: '',
        birthday: '',
        schRecCode: '',
        personTypeCode: '',
        personAddress: '',
        isAuth: '',
        workInitDate: '',
        enterAgencyDate: '',
        posCode: '',
        grCode: '',
        tecGrCode: '',
        salaGrCode: '',
        salaCardNo: '',
        salaCardBank: '',
        govCredCardNo: '',
        govCredCardBank: '',
        startDate: new Date(),
        nation: '',
        isUniSala: '',
        retireDate: '',
        workingYear: '',
        personIdeCode: '',
        deleteType: '',
        fundmode: '',
        isSpecialPost: '',
        personTypeId: '',
        postId: '',
        gradeId: '',
        levelId: '',
        personnelCode: '',
        outToAgency: '', // 去向单位id
        toAgencyName: '', // 去向单位名称
        outAgencySalaryMonth: '', //去向单位月份
        phone: '',
        funcName: '', //支出功能科目
        funcId: '',
        funcCode: ''
      },
      addDialogTitle: '新增人员',
      addFormVisible: false,
      isEdit: false,
      isable: true,
      registerFormVisible: false,//修改弹窗状态
      quitFormVisible: false,
      dialogImportFormVisible: false,
      updateFormVisible: false,//取消跨行修改
      updateFormVisibleLoading: false,
      checkAll: false,
      indeterminate: false,
      updateStatus: '',
      dialogStatus: '',
      funcLists: [],
      dialogTitle: '',
      sexLists: [], // 性别
      natLists: [], // 民族
      citTypeLists: [], // 证件类型代码
      schrecLists: [], // 学历
      posgrLists: [], // 职务
      grLists: [], // 职级
      tecgrLists: [], // 技术等级
      salagrLists: [], // 工资级别
      agencyBankLists: [], // 银行
      allBankLists: [],
      countryLists: [], // 国籍
      personPerideLists: [], // 人员身份
      fundmodeLists: [], // 人员经费保障方式
      salaryTypes: [],//工资类型
      IsfuncName: '',//是否显示支出功能科目
      personTypeList: [],
      postList: [],
      gradeList: [],
      levelList: [],
      registerFormRules: {
        agencyCode: [
          { required: true, message: '请输入单位代码', trigger: 'blur' }
        ],
        agencyName: [
          { required: true, message: '请输入单位名称', trigger: 'blur' }
        ],
        meritPayCode: [
          { required: true, message: '请输入工资类别', trigger: 'blur' }
        ],
        personName: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ],
        sexCode: [{ required: true, message: '请输入性别', trigger: 'blur' }],
        // natCode: [{ required: true, message: '请输入民族', trigger: 'blur' }],
        idenTypeCode: [
          { required: true, message: '请输入证件类型', trigger: 'blur' }
        ],
        idenNo: [
          { required: true, message: '请输入证件号码', trigger: 'blur' },
          {
            pattern: /((^[1-9]\d{5}(18|19|([23]\d))\d{2}(((0[13578]|10|12)(0[1-9]|[12]\d|3[01]))|((0[469]|11)(0[1-9]|[12]\d|30))|(02(0[1-9]|[12]\d)))\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}(((0[13578]|10|12)(0[1-9]|[12]\d|3[01]))|((0[469]|11)(0[1-9]|[12]\d|30))|(02(0[1-9]|[12]\d)))\d{3}$))|(^[\u4E00-\u9FA5](字第)([0-9a-zA-Z]{4,10})(号?)$)/,
            message: '证件号码格式有误！',
            trigger: 'blur'
          }
        ],
        salaCardNo: [
          { required: true, message: '请输入工资卡卡号', trigger: 'blur' },
          {
            // pattern: /^([1-9]{1})(\d{14}|\d{15}|\d{16}|\d{17}|\d{18})$/,
            pattern: /^[0-9]{1}\d+$/,
            message: '请输入正确的银行卡号',
            trigger: 'blur'
          }
        ],
        salaCardBank: [
          { required: true, message: '请输入工资卡开户银行', trigger: 'blur' }
        ],
        startDate: [
          { required: true, message: '请输入生效时间', trigger: 'blur' }
        ],
        funcName: [
          { required: true, message: '请输入支出功能科目', trigger: 'blur' }
        ],
        // nation: [{ required: true, message: '请输入国籍', trigger: 'blur' }],
        // personIdeCode: [
        //   { required: true, message: '请输入人员身份', trigger: 'blur' }
        // ],
        fundmode: [
          // { required: true, message: '请输入经费保障方式', trigger: 'blur' }
        ],
        isSpecialPost: [
          // { required: true, message: '请输入是否特殊岗位', trigger: 'blur' }
        ],
        // personTypeId: [
        //   { required: true, message: '请选择人员类别', trigger: 'blur' }
        // ],
        // postId: [
        //   { required: true, message: '请选择职务', trigger: 'blur' }
        // ],
        // gradeId: [
        //   { required: true, message: '请选择岗位', trigger: 'blur' }
        // ],
        // levelId: [
        //   { required: true, message: '请选择级别', trigger: 'blur' }
        // ]
      },
      quitFormRules: {
        personName: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ],
        sexCode: [{ required: true, message: '请输入性别', trigger: 'blur' }],
        meritPayCode: [
          { required: true, message: '请输入工资类别', trigger: 'blur' }
        ],
        idenNo: [
          { required: true, message: '请输入身份证号码', trigger: 'blur' },
          {
            pattern: /((^[1-9]\d{5}(18|19|([23]\d))\d{2}(((0[13578]|10|12)(0[1-9]|[12]\d|3[01]))|((0[469]|11)(0[1-9]|[12]\d|30))|(02(0[1-9]|[12]\d)))\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}(((0[13578]|10|12)(0[1-9]|[12]\d|3[01]))|((0[469]|11)(0[1-9]|[12]\d|30))|(02(0[1-9]|[12]\d)))\d{3}$))|(^[\u4E00-\u9FA5](字第)([0-9a-zA-Z]{4,10})(号?)$)/,
            message: '证件号码格式有误！',
            trigger: 'blur'
          }
        ],
        salaCardBank: [
          { required: true, message: '请输入工资卡开户银行', trigger: 'blur' }
        ],
        salaCardNo: [
          { required: true, message: '请输入工资卡卡号', trigger: 'blur' },
          {
            pattern: /^[0-9]{1}\d+$/,
            message: '请输入正确的银行卡号',
            trigger: 'blur'
          }
        ]
      },
      outFormRules: {
        agencyCode: [
          { required: true, message: '请输入原单位代码', trigger: 'blur' }
        ],
        agencyName: [
          { required: true, message: '请输入原单位名称', trigger: 'blur' }
        ],
        personName: [
          { required: true, message: '请输入人员姓名', trigger: 'blur' }
        ],
        idenNo: [
          { required: true, message: '请输入身份证号码', trigger: 'blur' }
        ],
        startDate: [
          { required: true, message: '请输入生效时间', trigger: 'blur' }
        ],
        toAgencyName: [
          { required: true, message: '请输入去向单位', trigger: 'blur' }
        ]
      },
      reductionFormRules: {

        deleteType: [
          { required: true, message: '请输入人员消减类型', trigger: 'blur' }
        ]

      },
      outFormVisible: false, // 调出弹出框状态
      agencyData: [], // 树数据集合
      operatePersonLists: [], // 操作人员集合
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      showTree: false, // 是否显示树
      reductionFormVisible: false, // 消减弹出框状态
      registerLoading: false, // 在职页面保存按钮loading
      quitLoading: false, // 离休页面保存按钮loading
      outLoading: false, // 调出页面保存按钮loading
      reducationLoading: false // 消减页面保存按钮loading
    }
  },
  watch: {
    'formData.toAgencyName'(val) {
      if (val) {
        this.$refs.tree.filter(val)
      }
    },
    personSalaryLists: {
      immediate: true,
      deep: true,
      handler(val) {
        this.calculate(val)
      }
    },
    // 表格的数据数组
    // list(val) {
    //   this.doLayout()
    // },
    treeData(val) {
      if (val && val.isleaf === '1') {
        this.handleTree(val)
      }
    }
  },
  mounted() {
    this.getTbHeight()
  },
  beforeMount() {
    window.addEventListener('resize', this.getTbHeight)
  },
  //页面初始时执行的方法
  created() {
    getfuncName().then(res => {
      this.IsfuncName = res.data
    })
    this.initDict()
    this.initBaseInfo()
    if (this.treeData && this.treeData.isleaf === '1') {
      this.listQuery.agencyId = this.treeData.id
      this.listQuery.agencyCode = this.treeData.label.split('-')[0]
      this.listQuery.agencyName = this.treeData.label.split('-')[1]
      this.unitName = this.treeData.label.split('-')[1]
      this.formData.agencyId = this.treeData.id
      this.formData.agencyCode = this.treeData.label.split('-')[0]
      this.formData.agencyName = this.treeData.label.split('-')[1]
      this.listQuery.flag = this.tabPane

      this.handleFilter()
      // 获取在职和离休人数
      this.getStateNum()
      this.getSalaryState()

      this.getTree()
      this.initDeptDict()
      this.getBankByAgencyId()//获取单位代发行
    }
  },
  methods: {

    // 获取数内容
    getTree() {
      getDepartmentTree(this.listQuery).then(response => {
        this.listTree = response.data
      })
    },
    // 清除下拉树选中
    clearHandle() {
      this.listQuery.deptName = ''
      this.listQuery.deptId = null
      this.defaultExpandedKey = []
    },
    // 树点击
    handleDeptNodeClick(data) {
      this.listQuery.deptId = data.id
      this.listQuery.deptName = data.label
      if (this.listQuery.deptName === '组织机构') {
        this.listQuery.deptId = ''
        this.listQuery.deptName = ''
      } else {
        this.$refs.selectReport.blur()
      }
    },

    tabChange(tab, event) {
      if (tab.name === 'enclosure') {
        this.$refs.fileRef.attachmentPreservation(this.formData.personId, this.formData.agencyId)
      }
    },
    // 获取人员工资信息
    getPersonSalaryInfo() {
      const queryParam = {}
      queryParam['agencyId'] = this.formData.agencyId
      queryParam['personId'] = this.formData.personId
      queryParam['personType'] = this.formData.meritPayCode
      if (queryParam.personId) {
        getPersonSalaryInfo(queryParam).then(response => {
          response.data.forEach(item => {
            if (item.value === '' || item.value === 0 || !item.value) {
              item.value = null
            }
          })
          this.personSalaryLists = response.data
        })
      } else {
        this.personSalaryLists = []
      }
    },
    // 获取单位限制数
    async queryAgencyPersonRestrict() {
      const queryParam = {}
      queryParam['agencyId'] = this.formData.agencyId
      queryParam['payCode'] = this.formData.meritPayCode
      if (queryParam.payCode) {
        await queryAgencyPersonRestrict(queryParam).then(response => {
          this.agencyPersonRestrict = response.data//编制数限制数

        })
      }
    },
    // 获取单位现有人数
    async queryExistingNumber() {
      const queryParam = {}
      queryParam['agencyId'] = this.formData.agencyId
      queryParam['payCode'] = this.formData.meritPayCode
      if (queryParam.payCode) {
        await queryExistingNumber(queryParam).then(response => {
          this.existingNumber = response.data//现有人数
        })
      }
    },
    //选择人员类型后获取该人员类型工资项
    async getPersonSalaryInfoByPersonType() {
      await this.queryExistingNumber()//获取现有人数
      await this.queryAgencyPersonRestrict()//获取人员编制限制数
      if (this.agencyPersonRestrict !== '' && this.existingNumber !== '' && this.agencyPersonRestrict <= this.existingNumber) {
        this.$message({
          showClose: true,
          message: '人员编制数已满！无法新增人员',
          type: 'warning',
          duration: 4000
        })
        return
      }
      this.getPersonSalaryInfo()
    },
    calculate(personSalaryLists) {
      // 获取每一行的数据进行计算
      for (const submit of personSalaryLists) {
        for (const computeFormula of this.computeFormula) {
          //判断当前人员类型的公式
          const meritPayCode = computeFormula.meritPayCode.split(',')
          if (meritPayCode.includes(this.formData.meritPayCode)) {
            const formula = computeFormula.computeFormula
            //获取小数位数
            const decimalPlace = computeFormula.decimalPlace
            const equation = formula.split('=')
            const answer = equation[0]
            const args = equation[1].split(',')
            let calc = ''
            for (let arg of args) {
              if (arg.startsWith('&') && arg.endsWith('&')) {
                arg = arg.substring(1, arg.length - 1)
                if (arg !== 'null') {
                  let subitemValue = 0
                  for (const submit_item of personSalaryLists) {
                    if (submit_item.columnName === arg) {
                      subitemValue = submit_item.value === null ? 0 : submit_item.value
                      // calc += submit_item.value === '' ? '0' : submit_item.value
                    }
                  }
                  calc += subitemValue
                } else {
                  calc += 0
                }
              } else {
                calc += arg
              }
            }
            if (submit.columnName === answer) {
              submit.value = Number(this.$math.round(this.$math.evaluate(calc), decimalPlace))
            }
          }
        }
      }
    },
    // 生成计算公式
    initDict() {
      generateFormula(this.formData.agencyId)
        .then(res => {
          this.computeFormula = res.data
        })
        .catch(() => {
          this.computeFormula = []
        })
    },
    // 获取table高度的方法
    getTbHeight() {
      this.tableHeight = window.innerHeight - 315
    },
    /* 重新渲染table组件 */
    // doLayout() {
    //   this.$nextTick(() => {
    //     this.$refs.singalTable.doLayout()
    //   })
    // },
    // 身份证获取生日
    getName(iden) {
      const val = iden.length
      let birth = null
      const myDate = new Date()
      const month = myDate.getMonth() + 1
      const day = myDate.getDate()
      let age = 0 // eslint-disable-line no-unused-vars
      if (val === 18) {
        birth =
          iden.substring(6, 10) +
          '-' +
          iden.substring(10, 12) +
          '-' +
          iden.substring(12, 14)
        age = myDate.getFullYear() - iden.substring(6, 10) - 1
        if (
          iden.substring(10, 12) < month ||
          (iden.substring(10, 12) === month && iden.substring(12, 14) <= day)
        ) { age++ }
      }
      if (val === 15) {
        birth =
          '19' +
          iden.substring(6, 8) +
          '-' +
          iden.substring(8, 10) +
          '-' +
          iden.substring(10, 12)
        age = myDate.getFullYear() - iden.substring(6, 8) - 1901
        if (
          iden.substring(8, 10) < month ||
          (iden.substring(8, 10) === month && iden.substring(10, 12) <= day)
        ) { age++ }
      }

      this.formData.birthday = birth
    },

    // 双击
    editclick(row) {

      if (this.tabPane === '2') {
        return
      } else {
        if (this.salaryState === 1) {
          this.$emit('salaryStateCallback')
          return
        }
        this.isEdit = true
        this.disable = false
        const selection = row.row
        //   if (selection.length !== 1) {
        //   this.$message({
        //     showClose: true,
        //     message: '请选择一条数据',
        //     type: 'warning',
        //     duration: 2000
        //   })
        //   return
        // }

        const operateCode = selection.operateCode
        const verifyState = selection.verifyState
        const isReal = selection.isReal
        if (verifyState === '2' && isReal === 0) {
          this.$message({
            showClose: true,
            message: '未生效数据不允许修改',
            type: 'warning',
            duration: 4000
          })
          return
        }
        // 如果上一次是编辑，并且已送审核，则不允许修改
        if (operateCode === 'edit' && verifyState === '1') {
          this.$message({
            showClose: true,
            message: '请完成上一操作的审核后再进行操作',
            type: 'warning',
            duration: 4000
          })
          return
        }
        // 如果上一次是新增，并且已送审核，则不允许修改
        if (operateCode === 'add' && verifyState === '1') {
          this.$message({
            showClose: true,
            message: '请完成上一操作的审核后再进行操作',
            type: 'warning',
            duration: 4000
          })
          return
        }
        // 如果上一操作不是编辑或者新增，则必须审核通过后才可以操作
        if (
          operateCode !== 'edit' &&
          operateCode !== 'add' &&
          verifyState !== '2'

        ) {
          this.$message({
            showClose: true,
            message: '请完成上一操作的审核后再进行操作',
            type: 'warning',
            duration: 4000
          })
          return
        }
        let refForm = 'registerForm'
        // 离休人员编辑
        if (selection.state === '1') {
          this.dialogStatus = '修改离退休人员'
          this.dialogTitle = '修改-离退休人员'
          this.quitFormVisible = true
          this.formData = selection
          let state = false
          //判断银行是否准确
          if (this.agencyBankLists instanceof Array) {
            this.agencyBankLists.forEach(item => {
              if (item.code === this.formData.salaCardBank) {
                state = true
              }
            })

            if (!state) {
              for (const item in this.allBankLists) {
                if (this.allBankLists[item].code === this.formData.salaCardBank) {
                  this.formData.salaCardBank = this.allBankLists[item].name
                }
              }
            }
          }
          this.formData.agencyName = this.listQuery.agencyName
          const workInitDate = selection.workInitDate

          if (workInitDate !== null) {
            const workYear = workInitDate.split('-')[0]
            const currentYear = new Date().getFullYear()
            this.formData.workingYear = currentYear - workYear
          }
          refForm = 'registerForm'
        } else if (selection.state === '3') {
          // 在职人员编辑
          this.dialogStatus = '修改在职人员'
          this.dialogTitle = '修改-在职人员'
          this.registerFormVisible = true
          this.formData = selection
          this.formData.agencyName = this.listQuery.agencyName
          this.queryPostList('edit')
          this.queryGradeLevelList('edit')
          let state = false
          //判断银行是否准确
          if (this.agencyBankLists instanceof Array) {
            this.agencyBankLists.forEach(item => {
              if (item.code === this.formData.salaCardBank) {
                state = true
              }
            })

            if (!state) {
              for (const item in this.allBankLists) {
                if (this.allBankLists[item].code === this.formData.salaCardBank) {
                  this.formData.salaCardBank = this.allBankLists[item].name
                }
              }
            }
          }
          refForm = 'quitForm'
        }
        this.getPersonSalaryInfo() // 获取工资信息
        this.initDict() // 生成计算公式
        // this.$nextTick(() => {
        //   this.$refs[refForm].clearValidate()
        // })
      }
    },
    // 导入
    importFile() {
      if (this.salaryState === 1) {
        this.$emit('salaryStateCallback')
        return
      }
      this.dialogImportFormVisible = true
    },
    // 查询
    query() {
      this.dialogQueryFormVisible = true
    },
    // 上传文件
    uploadExcel(item) {
      const fileObj = item.file
      // FormData 对象
      const form = new FormData()
      // 文件对象
      form.append('file', fileObj)
      form.append("agencyId", this.formData.agencyId);
      Import(form).then(response => {
        this.$message({
          showClose: true,
          message: '导入成功',
          type: 'success',
          duration: 4000
        })
        this.dialogImportFormVisible = false
      }).then(() => {
        this.getList()
      })
    },
    getList() {
      this.listLoading = true
      getPersonOperateList(this.listQuery).then(response => {
        this.list = response.data.rows
        this.total = response.data.total
        this.listLoading = false
        this.clearCheckInput()
      })
    },
    //获取标准工资数值
    getSalaryByGradeLevel(data) {

      const form = { 'gradeLevelId': data }
      getSalByGradeLevelId(form).then(response => {
        //获取回显的工资数值
        for (const submit_item of this.personSalaryLists) {
          if (response.data instanceof Array) {
            response.data.forEach(element => {
              if (submit_item.keyId === element.salaryId) {
                submit_item.value = element.salaryMoney
              }
            })
          }

        }
      })
    },
    //清空查询条件
    clearCheckInput() {
      this.listQuery.deptName = ''
      this.listQuery.deptId = ''
      this.listQuery.meritPayCode = ''
      this.listQuery.posCode = ''
      this.listQuery.grCode = ''
      this.listQuery.personName = ''
      this.listQuery.idenNo = ''
      this.listQuery.state = ''
      this.listQuery.personnelCode = ''
    },
    handleFilter() {
      this.getList()
    },
    handleQuery() {
      this.listQuery.page = 1
      this.getList()
      this.dialogQueryFormVisible = false
    },
    restetFormData() {
      this.formData = {
        deptId: '',
        deptName: '',
        id: '',
        state: this.formData.state,
        agencyId: this.listQuery.agencyId,
        agencyCode: this.listQuery.agencyCode,
        agencyName: this.listQuery.agencyName,
        meritPayCode: '',
        personName: '',
        sexCode: '',
        natCode: '',
        idenTypeCode: '',
        idenNo: '',
        birthday: '',
        schRecCode: '',
        personTypeCode: '',
        personAddress: '',
        isAuth: '',
        workInitDate: '',
        enterAgencyDate: '',
        posCode: '',
        grCode: '',
        tecGrCode: '',
        salaGrCode: '',
        salaCardNo: '',
        salaCardBank: '',
        govCredCardNo: '',
        govCredCardBank: '',
        startDate: new Date(),
        nation: '',
        isUniSala: '',
        retireDate: '',
        workingYear: '',
        personIdeCode: '',
        deleteType: '',
        fundmode: '',
        isSpecialPost: '',
        personTypeId: '',
        postId: '',
        gradeId: '',
        levelId: '',
        outToAgency: '', // 去向单位id
        toAgencyName: '', // 去向单位名称
        phone: '', // 去向单位名称
        funcName: '', //支出功能科目
        funcId: '',
        funcCode: ''
      }
    },
    // 打开选择人员页面
    handleAdd() {
      if (this.salaryState === 1) {
        this.$emit('salaryStateCallback')
        return
      }
      this.formData.state = ''
      this.addFormVisible = true
    },
    // 生成uuid
    uuid() {
      var s = []
      var hexDigits = '0123456789abcdef'
      for (var i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1)
      }
      s[14] = '4' // bits 12-15 of the time_hi_and_version field to 0010
      s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1) // bits 6-7 of the clock_seq_hi_and_reserved to 01
      s[8] = s[13] = s[18] = s[23] = ''

      var uuid = s.join('')
      return uuid
    },
    // 新增页面选择人员按钮确定按钮
    handleAddDialog() {
      this.isEdit = false
      // this.getBankByAgencyId()//获取单位代发行
      if (this.formData.state === '3') {
        // 新增在职人员
        this.restetFormData()

        // this.getBankByAgencyId()//获取单位代发行

        if (this.agencyBankLists.length === 1) {
          this.disable = true
          this.formData.salaCardBank = this.agencyBankLists[0].code
        }
        this.registerFormVisible = true
        // this.addFormVisible = false
        this.dialogStatus = '新增在职人员'
        this.dialogTitle = '新增-在职人员'
        this.addFormVisible = false

        this.$nextTick(() => {
          this.$refs['registerForm'].clearValidate()
        })
      } else if (this.formData.state === '1') {
        // 新增离休人员
        this.restetFormData()
        // this.formData.meritPayCode = '11'
        this.formData.personTypeCode = '11'
        this.quitFormVisible = true
        // this.getBankByAgencyId()//获取单位代发行

        if (this.agencyBankLists.length === 1) {
          this.disable = true
          this.formData.salaCardBank = this.agencyBankLists[0].code
        }
        // this.addFormVisible = false
        this.dialogStatus = '新增离退休人员'
        this.dialogTitle = '新增-离退休人员'
        this.addFormVisible = false
        this.$nextTick(() => {
          this.$refs['quitForm'].clearValidate()
        })
      } else {
        this.$message({
          showClose: true,
          message: '请选择人员类型',
          type: 'warning',
          duration: 4000
        })
      }
      const uuid = this.uuid()
      this.formData.personId = uuid
      this.activeName = 'personInfo'
      this.getPersonSalaryInfo() // 获取工资信息
      this.initDict() // 生成计算公式
      setTimeout(() => {
        this.$refs.fileRef.clear_tmp_list(this.formData.personId, this.formData.agencyId)
      }, 1000)
    },
    // 导出模板
    exportTemplate() {
      Export().then(response => {
        const link = document.createElement('a')
        const objectUrl = URL.createObjectURL(response)
        link.href = objectUrl
        link.download = '人员导出模板.xls'
        link.click()
        URL.revokeObjectURL(objectUrl)
      })
    },
    // 导出
    outPutFile() {
      outPutPersonOperateList(this.listQuery).then(response => {
        const link = document.createElement('a')
        const objectUrl = URL.createObjectURL(response)
        link.href = objectUrl
        link.download = '人员变动编辑.xls'
        link.click()
        URL.revokeObjectURL(objectUrl)
      })
    },
    // 编辑
    handleEdit() {
      if (this.salaryState === 1) {
        this.$emit('salaryStateCallback')
        return
      }

      this.isEdit = true
      this.disable = false
      const selection = this.$refs.singalTable.selection
      if (selection.length !== 1) {
        this.$message({
          showClose: true,
          message: '请选择一条数据',
          type: 'warning',
          duration: 4000
        })
        return
      }
      const operateCode = selection[0].operateCode
      const verifyState = selection[0].verifyState
      const isReal = selection[0].isReal
      if (verifyState === '2' && isReal === 0) {
        this.$message({
          showClose: true,
          message: '未生效数据不允许修改',
          type: 'warning',
          duration: 4000
        })
        return
      }
      // 如果上一次是编辑，并且已送审核，则不允许修改
      if (operateCode === 'edit' && verifyState === '1') {
        this.$message({
          showClose: true,
          message: '请完成上一操作的审核后再进行操作',
          type: 'warning',
          duration: 4000
        })
        return
      }
      // 如果上一次是新增，并且已送审核，则不允许修改
      if (operateCode === 'add' && verifyState === '1') {
        this.$message({
          showClose: true,
          message: '请完成上一操作的审核后再进行操作',
          type: 'warning',
          duration: 4000
        })
        return
      }
      // 如果上一次是待调入，并且已送审核，则不允许修改
      // if (operateCode === 'in' && verifyState != null) {
      //   this.$message({
      //     showClose: true,
      //     message: '请完成上一操作的审核后再进行操作',
      //     type: 'warning',
      //     duration: 4000
      //   })
      //   return
      // }
      // 如果上一操作不是编辑或者新增，则必须审核通过后才可以操作
      if (
        operateCode !== 'edit' &&
        operateCode !== 'add' &&
        verifyState !== '2'
      ) {
        this.$message({
          showClose: true,
          message: '请完成上一操作的审核后再进行操作',
          type: 'warning',
          duration: 4000
        })
        return
      }
      let refForm = 'registerForm'
      // 离休人员编辑
      if (selection[0].state === '1') {
        this.dialogStatus = '修改离退休人员'
        this.dialogTitle = '修改-离退休人员'
        this.quitFormVisible = true
        this.formData = Object.assign({}, this.formData, selection[0])
        this.formData.agencyName = this.listQuery.agencyName
        let state = false
        //判断银行是否准确
        if (this.agencyBankLists instanceof Array) {
          this.agencyBankLists.forEach(item => {
            if (item.code === this.formData.salaCardBank) {
              state = true
            }
          })

          if (!state) {
            for (const item in this.allBankLists) {
              if (this.allBankLists[item].code === this.formData.salaCardBank) {
                this.formData.salaCardBank = this.allBankLists[item].name
              }
            }
          }
        }
        const workYear = selection[0].workInitDate.split('-')[0]
        const currentYear = new Date().getFullYear()
        this.formData.workingYear = currentYear - workYear
        refForm = 'registerForm'
      } else if (selection[0].state === '3') {
        // 在职人员编辑
        this.dialogStatus = '修改在职人员'
        this.dialogTitle = '修改-在职人员'
        this.registerFormVisible = true
        this.formData = Object.assign({}, this.formData, selection[0])
        this.formData.agencyName = this.listQuery.agencyName
        this.queryPostList('edit')
        this.queryGradeLevelList('edit')
        let state = false
        //判断银行是否准确
        if (this.agencyBankLists instanceof Array) {
          this.agencyBankLists.forEach(item => {
            if (item.code === this.formData.salaCardBank) {
              state = true
            }
          })

          if (!state) {
            for (const item in this.allBankLists) {
              if (this.allBankLists[item].code === this.formData.salaCardBank) {
                this.formData.salaCardBank = this.allBankLists[item].name
              }
            }
          }
        }
        refForm = 'quitForm'
      }
      setTimeout(() => {
        // this.$refs[refForm].clearValidate()
        this.$refs.fileRef.clear_tmp_list(this.formData.personId, this.formData.agencyId)
      }, 1000)
      this.activeName = 'personInfo'
      this.getPersonSalaryInfo() // 获取工资信息
      this.initDict() // 生成计算公式
    },
    // 工资编报保存
    handleAddsalaryInfo() {
      const tmp_list = []
      const tmp_object = {
        agencyId: this.formData.agencyId,
        personId: this.formData.personId,
        id: this.personSalaryLists[0].id,
        columnNames: ''
      }
      for (let i = 0; i < this.personSalaryLists.length; i++) {
        if (this.personSalaryLists[i].value === '') {
          this.$message({
            message: '请完善工资信息',
            type: 'warning'
          })
          return
        }
        tmp_object.columnNames += ',' + this.personSalaryLists[i].columnName
        tmp_object[this.personSalaryLists[i].columnName] = this.personSalaryLists[i].value
        if (i === this.personSalaryLists.length - 1) {
          tmp_object.columnNames = tmp_object.columnNames.substring(1)
          tmp_list[0] = tmp_object
          submitData(tmp_list).then(res => { })
        }
      }
    },

    // 新增/编辑保存人员信息
    async handleAddPerson(formRef) {
      if (this.agencyPersonRestrict !== '' && this.existingNumber !== '' && this.agencyPersonRestrict <= this.existingNumber) {
        this.$message({
          showClose: true,
          message: '人员编制数已满！无法新增人员',
          type: 'warning',
          duration: 4000
        })
        return
      }
      const file_list = await this.$refs.fileRef.attachmentPreservation(this.formData.personId, this.formData.agencyId) // 获取真的附件列表，判断是否为空
      const tmp_list = await this.$refs.fileRef.get_tmp_list() // 获取假的附件列表，判断是否为空
      if ((file_list && file_list.length === 0) && (tmp_list && tmp_list.length === 0) && this.configCtrl == '1') {
        this.$message({
          message: '请上传附件！',
          type: 'warning'
        })
        return
      }
      this.$refs[formRef].validate(valid => {
        if (valid) {
          this.registerLoading = true
          this.quitLoading = true
          if (this.formData.state === '1') {
            //this.formData.meritPayCode = '11'
            this.formData.personTypeCode = '11'
          }
          const tempData = Object.assign({}, this.formData)
          tempData.outToAgency = ''
          tempData.deleteType = ''
          if (this.formData.id !== '') {
            // 编辑
            if (
              tempData.operateCode === 'add' &&
              (tempData.verifyState === '0' || tempData.verifyState === '-1')
            ) {
              tempData.operateCode = 'add'
            } else if (tempData.operateCode === 'in' &&
              (tempData.verifyState === '0' || tempData.verifyState === '-1' || tempData.verifyState === null)) {
              tempData.operateCode = 'in'
            } else {
              tempData.operateCode = 'edit'
              if (tempData.verifyState === '2') {
                tempData.verifyState = '0'
              }
            }
            let sstate = false
            //判断银行是否准确
            if (this.agencyBankLists instanceof Array) {
              this.agencyBankLists.forEach(item => {
                if (item.code === tempData.salaCardBank) {
                  sstate = true
                }
              })

              if (!sstate) {
                sstate = false
                this.$message({
                  showClose: true,
                  message: '请修改银行信息',
                  type: 'warning',
                  duration: 4000
                })
                this.registerLoading = false // 在职页面保存按钮loading
                return
              }
            }
            // let tmp = await this.$refs.fileRef.save() // 第三个页签保存  tmp = true 附件上传成功
            if (this.configCtrl == '1' && !this.$refs.fileRef.save()) {
              this.$message({
                showClose: true,
                message: '附件上传失败',
                type: 'warning',
                duration: 4000
              })
              return
            }
            savePersonInfo(tempData)
              .then(response => {
                if (response.rscode === '100000') {
                  this.handleAddsalaryInfo() // 第二个页签保存
                  this.$refs.fileRef.save() // 第三个页签保存
                  this.registerFormVisible = true
                  this.quitFormVisible = true
                  // this.$message({
                  //   showClose: true,
                  //   message: '更新成功',
                  //   type: 'success',
                  //   duration: 4000
                  // })
                  this.updateFormVisible = false
                  this.registerLoading = false // 在职页面保存按钮loading
                  this.quitLoading = false
                  this.registerFormVisible = false//页面关闭
                  this.quitFormVisible = false
                  this.handleFilter()
                }
              })
              .catch(() => {
                this.registerLoading = false
                this.quitLoading = false
              })
            // } else {

            // // 新增
            // tempData.operateCode = 'add'
            // savePersonInfo(tempData)
            //   .then(response => {
            //     if (response.rscode === '100000') {
            //       this.handleAddsalaryInfo() // 第二个页签保存
            //       this.$refs.fileRef.save() // 第三个页签保存
            //       this.registerFormVisible = true
            //       this.quitFormVisible = true
            //       this.$message({
            //         showClose: true,
            //         message: '保存成功',
            //         type: 'success',
            //         duration: 4000
            //       })

            //       this.registerFormVisible = true, // 调出弹出框状态
            //         this.registerLoading = false
            //       this.quitLoading = false
            //       this.handleFilter()
            //     }
            //   })
            //   .catch(() => {
            //     this.registerLoading = true
            //     this.quitLoading = false
            //   })
          }
          // 新增
          tempData.operateCode = 'add'

          savePersonInfo(tempData)
            .then(response => {
              // 离休页面保存按钮loading

              if (response.rscode === '100000') {
                this.handleAddsalaryInfo() // 第二个页签保存
                this.$refs.fileRef.save() // 第三个页签保存

                this.$message({
                  showClose: true,
                  message: '保存成功',
                  type: 'success',
                  duration: 4000
                })
                this.updateFormVisible = false
                this.registerLoading = false // 在职页面保存按钮loading
                this.quitLoading = false
                this.registerFormVisible = false//页面关闭
                this.quitFormVisible = false

                this.handleFilter()
              }
            })
            .catch(() => {
              this.registerLoading = false //在职页面保存按钮loading
              this.quitLoading = false

            })
        } else {
          this.$message({
            showClose: true,
            message: '人员信息未填报完整！请将必填项补充完整！',
            type: 'warning',
            duration: 4000
          })
        }
      })
    },
    handleAddPersonupdate(formRef) {
      this.$refs[formRef].validate(valid => {
        if (valid) {
          this.registerLoading = true
          this.quitLoading = true
          const tempData = Object.assign({}, this.formData)
          tempData.outToAgency = ''
          tempData.deleteType = ''
          if (this.formData.id !== '') {
            tempData.operateCode = 'in'


            let sstate = false
            //判断银行是否准确
            if (this.agencyBankLists instanceof Array) {
              this.agencyBankLists.forEach(item => {
                if (item.code === tempData.salaCardBank) {
                  sstate = true
                }
              })

              if (!sstate) {
                sstate = false
                this.$message({
                  showClose: true,
                  message: '请修改银行信息',
                  type: 'warning',
                  duration: 4000
                })
                this.registerLoading = false
                return
              }
            }
            tempData.verifyState = '0'
            savePersonInfo(tempData).then(response => {
              this.$message({
                showClose: true,
                message: '调入成功',
                type: 'success',
                duration: 4000
              })
              this.handleFilter()
            }).catch(() => {
              this.$emit('handleInCallback')
            })
            this.$emit('handleInCallback')
            this.updateFormVisible = false
            this.updateFormVisibleLoading = false


          }
        }
      })
    },
    handleOut() {
      if (this.salaryState === 1) {
        this.$emit('salaryStateCallback')
        return
      }
      // 调出
      this.formData.outToAgency = ''
      this.formData.startDate = ''
      const selection = this.$refs.singalTable.selection
      if (selection.length !== 1) {
        this.$message({
          showClose: true,
          message: '请选择一条数据',
          type: 'warning',
          duration: 4000
        })
        return
      }
      // this.$nextTick(() => {
      //   this.$refs['outForm'].clearValidate()
      // })
      const verifyState = selection[0].verifyState
      const isReal = selection[0].isReal
      if (verifyState === '2' && isReal === 0) {
        this.$message({
          showClose: true,
          message: '未生效数据不允许修改',
          type: 'warning',
          duration: 4000
        })
        return
      }
      if (verifyState !== '2') {
        this.$message({
          showClose: true,
          message: '请完成上一操作的审核后再进行操作',
          type: 'warning',
          duration: 4000
        })
        return
      }
      this.showTree = false
      this.outFormVisible = true
      this.restetFormData()
      this.formData = Object.assign({}, this.formData, selection[0])
      this.formData.startDate = new Date()
      let param = {}
      param = { agencyId: this.listQuery.agencyId }
      getAgencyTree(param).then(response => {
        this.agencyData = response.data
      })
      setTimeout(() => {
        this.$refs.fileRef.clear_tmp_list(this.formData.personId, this.formData.agencyId)
        this.$refs.fileRef.attachmentPreservation(this.formData.personId, this.formData.agencyId)
      }, 1000)
    },
    // 是否显示树
    handleShowTree() {
      this.showTree = !this.showTree
    },
    // 树节点点击
    handleNodeClick(data, node) {
      this.treeClickCount++
      if (this.treeClickCount >= 2) {
        return
      }
      this.timer = window.setTimeout(() => {
        if (this.treeClickCount === 1) {
          this.treeClickCount = 0
          this.handleNodeClickFun(data, '单击')
        } else if (this.treeClickCount > 1) {
          this.treeClickCount = 0
          this.handleNodeClickFun(data, '双击')
        }
      }, 300)
    },
    handleNodeClickFun(data, type) {
      if (!Object.prototype.hasOwnProperty.call(data, 'children')) {
        this.formData.toAgencyName = data.label
        this.formData.outToAgency = data.id
        if (type === '双击') {
          this.handleOutSave()
        }
      }
    },
    // 树过滤
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },
    // 调出保存
    async handleOutSave() {
      const file_list = await this.$refs.fileRef.attachmentPreservation(this.formData.personId, this.formData.agencyId) // 获取真的附件列表，判断是否为空
      const tmp_list = await this.$refs.fileRef.get_tmp_list() // 获取假的附件列表，判断是否为空
      if ((file_list && file_list.length === 0) && (tmp_list && tmp_list.length === 0) && this.configCtrl == '1') {
        this.$message({
          message: '请上传附件！',
          type: 'warning'
        })
        return
      }
      this.$refs['outForm'].validate(valid => {
        if (valid) {
          if (this.formData.outToAgency === '') {
            this.$message({
              showClose: true,
              message: '请选择去向单位',
              type: 'warning',
              duration: 4000
            })
            return
          }
          this.outLoading = true
          // 判断调出对方单位工资是否送审，如果已送审，不允许调出
          getAgencyVerifyByAgencyId(this.formData.outToAgency).then((response) => {
            this.formData.outAgencySalaryMonth = response.data.salaryMonth
            if (response.data.isSubmitInAgency === 1) {
              this.$message({
                showClose: true,
                message: '对方单位工资已送审，不允许调出',
                type: 'warning',
                duration: 4000
              })
              this.outLoading = false
              return
            } else {
              const tempData = Object.assign({}, this.formData)
              tempData.operateCode = 'out'
              tempData.deleteType = ''
              savePersonInfo(tempData).then(response => {
                this.outFormVisible = false
                this.$message({
                  showClose: true,
                  message: '调出成功',
                  type: 'success',
                  duration: 4000
                })
                this.$refs.fileRef.save() // 第三个页签保存
                this.outLoading = false
                this.handleFilter()
              }).catch(() => {
                this.outLoading = false
              })
            }
          }).catch(() => {
            this.outLoading = false
          })
        }
      })
    },
    // 调入
    handleIn() {
      if (this.salaryState === 1) {
        this.$emit('salaryStateCallback')
        this.$emit('handleInCallback')
        return
      }
      const selection = this.$refs.singalTable.selection
      if (selection.length !== 1) {
        this.$message({
          showClose: true,
          message: '请选择一条数据',
          type: 'warning',
          duration: 4000
        })
        this.$emit('handleInCallback')
        return
      }
      const operateCode = selection[0].operateCode
      const verifyState = selection[0].verifyState
      const isReal = selection[0].isReal
      const existsFile = selection[0].existsFile
      if (verifyState === '2' && isReal === 0) {
        this.$message({
          showClose: true,
          message: '未生效数据不允许修改',
          type: 'warning',
          duration: 4000
        })
        this.$emit('handleInCallback')
        return
      }
      if (verifyState === '2') {
        this.$message({
          showClose: true,
          message: '只能调入待调入的人员',
          type: 'warning',
          duration: 4000
        })
        this.$emit('handleInCallback')
        return
      }
      if (operateCode === 'in' && verifyState !== null) {
        this.$message({
          showClose: true,
          message: '请完成上一操作的审核后再进行操作',
          type: 'warning',
          duration: 4000
        })
        this.$emit('handleInCallback')
        return
      }
      if (operateCode !== 'in' && verifyState !== '2') {
        this.$message({
          showClose: true,
          message: '只能调入待调入的人员',
          type: 'warning',
          duration: 4000
        })
        this.$emit('handleInCallback')
        return
      }
      if (existsFile !== '1' && this.configCtrl == '1') {
        this.$message({
          showClose: true,
          message: '请上传附件！',
          type: 'warning',
          duration: 4000
        })
        this.$emit('handleInCallback')
        return
      }
      // 判断调入人员的银行与当前单位银行是否一致，如果不一致，需要提示修改
      const salaBankCode = selection[0].salaCardBank
      let isBank = false
      for (const index in this.agencyBankLists) {
        if (this.agencyBankLists[index].code === salaBankCode) {
          isBank = true
        }
      }
      if (isBank) {

        const tempData = Object.assign({}, selection[0])
        tempData.verifyState = '0'
        savePersonInfo(tempData)
          .then(response => {
            this.$message({
              showClose: true,
              message: '调入成功',
              type: 'success',
              duration: 4000
            })
            this.$emit('handleInCallback')
            this.handleFilter()
          })
          .catch(() => {
            this.$emit('handleInCallback')
          })

      } else {

        this.$emit('handleInCallback')
        this.updateFormVisible = true
        const selection = this.$refs.singalTable.selection
        this.formData = Object.assign({}, this.formData, selection[0])

        let state = false
        //判断银行是否准确
        if (this.agencyBankLists instanceof Array) {
          this.agencyBankLists.forEach(item => {
            if (item.code === this.formData.salaCardBank) {
              state = true
            }
          })

          if (!state) {
            for (const item in this.allBankLists) {
              if (this.allBankLists[item].code === this.formData.salaCardBank) {
                this.formData.salaCardBank = this.allBankLists[item].name
              }
            }
          }
        }
      }
    },
    // 调入 前做判断 单位实有人数是否大于单位限制人数  大于给与提示 不大于 则走调入方法
    async getPersonSalaryInfoByPersonTypes() {
      await this.queryExistingNumbers()//获取现有人数
      await this.queryAgencyPersonRestricts()
      if (this.agencyPersonRestrict !== '' && this.existingNumber !== '' && this.agencyPersonRestrict <= this.existingNumber) {
        this.$message({
          showClose: true,
          message: '人员编制数已满！无法新增人员',
          type: 'warning',
          duration: 4000
        })
        this.$emit('handleInCallback')
        return
      }
      this.handleIn()
    },
    checkisChangedPersonType() {
      if (this.formData.meritPayCode) {

      } else {
        this.$message({
          showClose: true,
          message: '请选择人员类型',
          type: 'warning',
          duration: 4000
        })
      }
    },
    // 获取单位限制数
    async queryAgencyPersonRestricts() {
      const selection = this.$refs.singalTable.selection
      const queryParam = {}
      queryParam['agencyId'] = selection[0].agencyId
      queryParam['payCode'] = selection[0].meritPayCode
      if (queryParam.payCode) {
        await queryAgencyPersonRestrict(queryParam).then(response => {
          this.agencyPersonRestrict = response.data//编制数限制数

        })
      }
    },
    // 获取单位现有人数
    async queryExistingNumbers() {
      const selection = this.$refs.singalTable.selection
      const queryParam = {}
      queryParam['agencyId'] = selection[0].agencyId
      queryParam['payCode'] = selection[0].meritPayCode
      if (queryParam.payCode) {
        await queryExistingNumber(queryParam).then(response => {
          this.existingNumber = response.data//现有人数
        })
      }
    },
    // 消减
    handleReduction() {
      if (this.salaryState === 1) {
        this.$emit('salaryStateCallback')
        return
      }
      this.formData.startDate = ''
      const selection = this.$refs.singalTable.selection
      if (selection.length !== 1) {
        this.$message({
          showClose: true,
          message: '请选择一条数据',
          type: 'warning',
          duration: 4000
        })
        return
      }
      const verifyState = selection[0].verifyState
      const isReal = selection[0].isReal
      if (verifyState === '2' && isReal === 0) {
        this.$message({
          showClose: true,
          message: '未生效数据不允许修改',
          type: 'warning',
          duration: 4000
        })
        return
      }
      if (verifyState !== '2') {
        this.$message({
          showClose: true,
          message: '请完成上一操作的审核后再进行操作',
          type: 'warning',
          duration: 4000
        })
        return
      }
      this.reductionFormVisible = true
      this.restetFormData()
      this.formData = Object.assign({}, this.formData, selection[0])
      this.formData.deleteType = ''
      this.formData.startDate = new Date()
      setTimeout(() => {
        this.$refs.fileRef.clear_tmp_list(this.formData.personId, this.formData.agencyId)
        this.$refs.fileRef.attachmentPreservation(this.formData.personId, this.formData.agencyId)
      }, 1000)
    },
    // 消减保存
    async handleReducationSave() {
      const file_list = await this.$refs.fileRef.attachmentPreservation(this.formData.personId, this.formData.agencyId) // 获取真的附件列表，判断是否为空
      const tmp_list = await this.$refs.fileRef.get_tmp_list() // 获取假的附件列表，判断是否为空
      if ((file_list && file_list.length === 0) && (tmp_list && tmp_list.length === 0) && this.configCtrl == '1') {
        this.$message({
          message: '请上传附件！',
          type: 'warning'
        })
        return
      }
      this.$refs['reductionForm'].validate(valid => {
        if (valid) {
          this.reducationLoading = true
          const tempData = Object.assign({}, this.formData)
          tempData.operateCode = 'delete'
          tempData.outToAgency = ''
          savePersonInfo(tempData)
            .then(response => {
              this.reductionFormVisible = false
              this.$message({
                showClose: true,
                message: '消减成功',
                type: 'success',
                duration: 4000
              })
              this.$refs.fileRef.save() // 第三个页签保存
              this.reducationLoading = false
              this.handleFilter()
            })
            .catch(() => {
              this.reducationLoading = false
            })
        }
      })
    },
    // 生效
    submitVerify() {
      if (this.salaryState === 1) {
        this.$emit('salaryStateCallback')
        this.$emit('verifyCallback')
        return
      }
      this.operatePersonLists = []
      const selection = this.$refs.singalTable.selection
      if (selection.length === 0) {
        this.$message({
          showClose: true,
          message: '请选择要生效的人员',
          type: 'warning',
          duration: 4000
        })
        this.$emit('verifyCallback')
        return
      }
      const personIds = []
      selection.forEach(item => {
        this.operatePersonLists.push(item)
        personIds.push(item.personId)
      })
      // 校验附件
      const params = {}
      params['personId'] = personIds.join(',')
      params['agencyId'] = this.listQuery.agencyId
      params['operateType'] = '2'
      queryPersonFileNum(params).then(response => {
        if (response.data === 0 && this.configCtrl == '1') {
          this.$message({
            showClose: true,
            message: '存在未上传附件的人员',
            type: 'warning',
            duration: 4000
          })
          this.$emit('verifyCallback')
          return
        }

        personApproved(this.operatePersonLists)
          .then(response => {
            this.$message({
              showClose: true,
              message: '生效成功',
              type: 'success',
              duration: 4000
            })
            this.$emit('verifyCallback')
            this.handleFilter()
          })
          .catch(() => {
            this.$emit('verifyCallback')
          })
      })
        .catch(() => {
          this.$emit('verifyCallback')
        })
      // })
    },
    // 撤销生效
    revokeVerify() {
      if (this.salaryState === 1) {
        this.$emit('salaryStateCallback')
        this.$emit('revokeVerifyCallback')
        return
      }
      this.operatePersonLists = []
      const selection = this.$refs.singalTable.selection
      if (selection.length > 1 || selection.length === 0) {
        this.$message({
          showClose: true,
          message: '请选择一条要撤销生效的人员',
          type: 'warning',
          duration: 4000
        })
        this.$emit('revokeVerifyCallback')
        return
      }

      rejectPersonApproved(selection[0])
        .then(response => {
          this.$message({
            showClose: true,
            message: '撤销生效成功',
            type: 'success',
            duration: 4000
          })
          this.$emit('revokeVerifyCallback')
          this.handleFilter()
        })
        .catch(() => {
          this.$emit('revokeVerifyCallback')
        })

    },
    // 撤销编辑
    handleDelete() {
      if (this.salaryState === 1) {
        this.$emit('salaryStateCallback')
        this.$emit('handleDeleteCallback')
        return
      }
      this.operatePersonLists = []
      const selection = this.$refs.singalTable.selection
      if (selection.length === 0) {
        this.$message({
          showClose: true,
          message: '请选择要撤销编辑的人员',
          type: 'warning',
          duration: 4000
        })
        this.$emit('handleDeleteCallback')
        return
      }
      selection.forEach(item => {
        this.operatePersonLists.push(item)
      })

      revokeOperate(this.operatePersonLists)
        .then(response => {
          this.$message({
            showClose: true,
            message: '撤销编辑成功',
            type: 'success',
            duration: 4000
          })
          this.$emit('handleDeleteCallback')
          this.handleFilter()
        })
        .catch(() => {
          this.$emit('handleDeleteCallback')
        })
      // })
      // .catch(() => {
      //   this.$emit('handleDeleteCallback')
      // })
    },
    // 新增离休人员时计算工龄
    calculationWorkYear(type) {
      if (type === 'workInitDate') {
        let retireYear = this.formData.retireDate
        if (retireYear !== '') {
          const workInitYear = this.formData.workInitDate.split('-')[0]
          retireYear = retireYear.split('-')[0]
          this.formData.workingYear = retireYear - workInitYear
        }
      } else if (type === 'retireDate') {
        let workInitYear = this.formData.workInitDate
        if (workInitYear !== '') {
          const retireYear = this.formData.retireDate.split('-')[0]
          workInitYear = workInitYear.split('-')[0]
          this.formData.workingYear = retireYear - workInitYear
        }
      }
    },
    // 获取在职和离职人数
    getStateNum() {
      getStateNum(this.listQuery).then(response => {
        if (response.data.registerNum !== []) {
          this.registerNum = response.data.registerNum + response.data.quitNum
        } else {
          this.registerNum = 0
        }
        if (response.data.quitNum !== []) {
          this.quitNum = response.data.quitNum
        } else {
          this.quitNum = 0
        }
      })
    },
    // 查询职务信息
    queryPostList(type) {
      if (type !== 'edit') {
        this.formData.postId = ''
        this.formData.gradeId = ''
        this.formData.levelId = ''
      }
      const params = { 'personTypeId': this.formData.personTypeId }
      querySalPostByPersonTypeId(params).then((response) => {
        this.postList = Object.assign(response.data)
      })
    },

    // 查询档次信息
    queryGradeLevelList(type) {
      if (type !== 'edit') {
        this.formData.gradeId = ''
        this.formData.levelId = ''
      }
      const params = { 'personTypeId': this.formData.personTypeId, 'postId': this.formData.postId, type: 'grade' }
      querySalPostGradeLevelAll(params).then((response) => {
        this.gradeList = Object.assign(response.data)
      })
      const params1 = { 'personTypeId': this.formData.personTypeId, 'postId': this.formData.postId, type: 'level' }
      querySalPostGradeLevelAll(params1).then((response) => {
        this.levelList = Object.assign(response.data)
      })
    },
    //初始化字典
    initDeptDict() {
      // 查询部门名称
      getDepartmentList({ agencyId: this.listQuery.agencyId })
        .then(res => {
          this.deptNames = res.data
        })
        .catch(() => {
          this.deptNames = []
        })
    },
    //初始化字典
    initBaseInfo() {
      getSex().then(response => {
        this.sexLists = Object.assign({}, response.data)
      })
      getNat().then(response => {
        this.natLists = Object.assign({}, response.data)
      })
      getCitType().then(response => {
        this.citTypeLists = Object.assign({}, response.data)
      })
      getSchrec().then(response => {
        this.schrecLists = Object.assign({}, response.data)
      })
      getPosgr().then(response => {
        this.posgrLists = Object.assign({}, response.data)
      })
      getGr().then(response => {
        this.grLists = Object.assign({}, response.data)
      })
      getTecgr().then(response => {
        this.tecgrLists = Object.assign({}, response.data)
      })
      getSalagr().then(response => {
        this.salagrLists = Object.assign({}, response.data)
      })
      getAgencyBank().then(response => {
        this.agencyBankLists = Object.assign({}, response.data)
        this.allBankLists = Object.assign({}, response.data)
      })
      getCountry().then(response => {
        this.countryLists = Object.assign({}, response.data)
      })
      getAgencyPeride().then(response => {
        this.personPerideLists = Object.assign({}, response.data)
      })
      getFundmode().then(response => {
        this.fundmodeLists = Object.assign({}, response.data)
      })
      querySalPersonTypeAll().then((response) => {
        this.personTypeList = Object.assign(response.data)
      })
      getSalaryType().then(response => {
        this.salaryTypes = Object.assign({}, response.data)
      })
      getConfigCtrlByTypeMof("fileVerify").then(response => {
        this.configCtrl = response.data
      })
      // 支出功能分类科目
      getBaseDataFunc().then((response) => {
        this.funcLists = response.data
      })
    },
    // 获取单位的银行
    getBankByAgencyId() {
      // 获取单位选择的银行，过滤掉单位未选择的银行
      queryAgencyInfoById(this.listQuery).then(response => {
        let agencyBank = response.data[0].agencyBankName
        if (agencyBank !== '' && agencyBank != null && agencyBank !== []) {
          if (this.allBankLists !== []) {
            const temp = []
            agencyBank = agencyBank.substring(1, agencyBank.length - 1).split(',')
            for (const item in this.allBankLists) {
              for (const index in agencyBank) {
                if (this.allBankLists[item].code === agencyBank[index]) {
                  const value = this.allBankLists[item]
                  temp.push(value)
                }
              }
            }
            this.agencyBankLists = temp
          }
        } else {
          this.agencyBankLists = []
        }
      })
    },
    // 树点击
    handleFuncNodeClick(data) {
      console.log(data)
      if (data.isleaf === '1') {
        this.formData.funcCode = data.code
        this.formData.funcName = data.label
        this.formData.funcId = data.id
        this.$refs.selectReport.blur()
      }
    },
    // 附件方法
    appendixOpen() {
      if (this.salaryState === 1) {
        this.$emit('salaryStateCallback')
        return
      }
      // this.selection = this.$refs.singalTable.selection
      // if (this.selection.length === 0) {
      //   this.openenClose = false
      // }
      // const personList = []
      // this.selection.forEach(item => {
      //   personList.push({ id: item.personId })
      // })
      // if (this.tabPane === '0' || this.tabPane === '-1') {
      //   this.openenClose = true
      // }
      // this.$refs.enc.appendixOpen(personList, this.openenClose, undefined, this.listQuery.agencyId)
      this.selection = this.$refs.singalTable.selection
      if (this.selection.length > 0) {
        const arr = []
        for (let i = 0; i < this.selection.length; i++) {
          arr.push(this.selection[i].personName)
        }
        this.$confirm("当前操作" + arr + ' 提示!', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          this.openenClose = true
          const personList = []
          this.selection.forEach(item => {
            personList.push({ id: item.personId })
          })
          this.$refs.enc.appendixOpen(personList, this.openenClose, undefined, this.listQuery.agencyId)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消上传'
          });
        });
      } else {
        this.openenClose = false
        const personList = []
        this.selection.forEach(item => {
          personList.push({ id: item.personId })
        })
        if (this.tabPane === '0' || this.tabPane === '-1') {
          this.openenClose = true
        }
        this.$refs.enc.appendixOpen(personList, this.openenClose, undefined, this.listQuery.agencyId)
      }
      this.getList()
    },
    // 查看详情
    viewInfo(currenRow) {
      let personState
      const operateType = undefined
      const agencyIds = this.listQuery.agencyId
      if (currenRow.operateCode === 'in' && currenRow.verifyState === null) {
        personState = '待调入'
      }
      this.$refs.personSalaryInfo.viewInfo(currenRow.personId, operateType, agencyIds, personState)
    },
    // 查询工资编报状态
    getSalaryState() {
      getSalaryState(this.listQuery).then(response => {
        this.salaryState = response.data.is_submit_in_agency
      })
    },
    handleTree(data) {
      this.listQuery.agencyId = data.id
      this.listQuery.agencyCode = data.label.split('-')[0]
      this.listQuery.agencyName = data.label.split('-')[1]
      this.unitName = data.label.split('-')[1]
      this.formData.agencyId = data.id
      this.formData.agencyCode = data.label.split('-')[0]
      this.formData.agencyName = data.label.split('-')[1]
      this.listQuery.flag = this.tabPane
      this.initBaseInfo()
      this.getBankByAgencyId()//获取单位代发行
      this.handleFilter()
      this.getTree()
      // 获取在职和离休人数
      this.getStateNum()
      this.getSalaryState()
      this.initDeptDict()
    },
    // 全选
    handleCheckAll(val) {
      const checked = val.checked;
      for (let i = 0; i < this.list.length; i++) {
        this.list[i].check = checked;
      }
      this.checkAll = true;
      this.indeterminate = false;
      this.checkList = [];
      if (checked) {
        for (const item of this.list) {
          if (item.check) {
            this.checkList.push(item);
          }
        }
      }
    },// 点击多选按钮
    handleCheck() {
      this.checkList = [];
      const totalCount = this.list.length - 1;
      let isCheckedCount = 0;
      this.list.forEach((item) => {
        if (item.check) {
          this.checkList.push(item);
          isCheckedCount++;
        }
      });
      this.checkAll = totalCount === isCheckedCount;
      this.indeterminate = isCheckedCount > 0 && isCheckedCount < totalCount;
    }
  }
}
</script>
<style lang="scss" scoped>
@import "~@/styles/border.scss";

/*引入公共样式*/
.addForm {
  text-align: center;

  .selectSpan {
    margin-right: 40%;
    font-size: 18px;
    font-weight: 500;
  }

  .addSelectRow {
    margin-top: 3%;
  }

  .addButRow {
    margin-top: 5%;
  }

  .addTitpsRow {
    margin-top: 8%;
    margin-bottom: 8%;

    .addTitps {
      font-size: 18px;
      color: #ff0000;
      font-weight: 600;
    }
  }
}

.el-row-out {
  display: flex;
  flex-wrap: wrap;

  .el-tree-out {
    height: auto;
    max-height: 500px;
    overflow: auto;
  }

  .tipsCol {
    margin-top: 5%;
  }

  .tipsSpan {
    color: #ff0000;
    font-size: 18px;
    font-weight: 600;
  }
}

.reductionTipsCol {
  margin-bottom: 20px;

  .reductionTips {
    color: #ff0000;
    font-size: 14px;
    font-weight: 600;
    margin-left: 5%;
    margin-bottom: 5%;
  }
}

.numCol {
  margin-top: 10px;

  span {
    font-size: 16px;
  }
}

.treewidth .el-row-out .el-tree-out[data-v-a4a4fa96] {
  height: 413px;
}

.redstar .el-form-item__error {
  margin-top: 45px !important;
}
</style>